<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Auth::routes();

Route::get('/', 'HomeController@index')->middleware('auth');

Route::group(['middleware' => ['auth', 'role:1'], 'namespace' => 'Student', 'prefix' => 'student'], function () {
    Route::get('/', 'HomeController@index');
    Route::resource('twowaychoice', 'TwowayChoiceController');

    Route::get('/setting/profile', 'SettingController@edit_profile');
    Route::post('/setting/profile', 'SettingController@store_profile');

    Route::get('/setting/password', 'SettingController@edit_password');
    Route::post('/setting/password', 'SettingController@store_password');

    Route::get('/thesis/edittitle', 'ThesisController@edit_title');
    Route::post('/thesis/edittitle', 'ThesisController@store_title');

    Route::get('/thesis/editdescription', 'ThesisController@edit_description');
    Route::post('/thesis/storedescription', 'ThesisController@store_description');

    Route::get('/thesis/editproposal', 'ThesisController@edit_proposal');
    Route::post('/thesis/storeproposal', 'ThesisController@store_proposal');

    Route::get('/thesis/editpaper', 'ThesisController@edit_paper');
    Route::post('/thesis/storepaper', 'ThesisController@store_paper');

});

Route::group(['middleware' => ['auth', 'role:2'], 'namespace' => 'Supervisor', 'prefix' => 'supervisor'], function () {
    Route::get('/', 'HomeController@index');
    Route::resource('/twowaychoice', 'TwowayChoiceController');

    Route::get('/setting/profile', 'SettingController@edit_profile');
    Route::post('/setting/profile', 'SettingController@store_profile');
    Route::get('/setting/password', 'SettingController@edit_password');
    Route::post('/setting/password', 'SettingController@store_password');

    Route::get('/thesis/edittitle', 'ThesisController@edit_title');
    Route::get('/thesis/checktitle/{student_id}', 'ThesisController@check_title');
    Route::post('/thesis/storetitle', 'ThesisController@store_title');

    Route::get('/thesis/description', 'ThesisController@listdescription');
    Route::get('/thesis/checkdescription/{student_id}', 'ThesisController@check_description');
    Route::post('/thesis/storedescription', 'ThesisController@store_description');
    Route::post('/thesis/storedescriptionfile', 'ThesisController@store_descriptionfile');

    Route::get('/thesis/proposal', 'ThesisController@listproposal');
    Route::get('/thesis/checkproposal/{student_id}', 'ThesisController@check_proposal');
    Route::post('/thesis/storeproposal', 'ThesisController@store_proposal');
    Route::post('/thesis/storeproposalfile', 'ThesisController@store_proposalfile');

    Route::get('/thesis/paper', 'ThesisController@listpaper');
    Route::get('/thesis/checkpaper/{student_id}', 'ThesisController@check_paper');
    Route::post('/thesis/storepaper', 'ThesisController@store_paper');
    Route::post('/thesis/storepaperfile', 'ThesisController@store_paperfile');

    Route::get('/thesis/editreview/{student_id}', 'ThesisController@edit_review');
    Route::post('/thesis/storeview', 'ThesisController@store_review');
    Route::get('/thesis/down_grade/{student_id}',  'ThesisController@down_grade');


    Route::get('/thesis/list_supervise_comment', 'ThesisController@list_supervise_comment');
    Route::get('/thesis/supervise_comment/{student_id}', 'ThesisController@supervise_comment');
    Route::post('/thesis/supervise_comment/', 'ThesisController@supervise_comment_store');

    Route::get('/thesis/list_review_comment', 'ThesisController@list_review_comment');
    Route::get('/thesis/review_comment/{student_id}', 'ThesisController@review_comment');
    Route::post('/thesis/review_comment/', 'ThesisController@review_comment_store');

    Route::get('/thesis/list_defense_comment', 'ThesisController@list_defense_comment');
    Route::get('/thesis/defense_comment/{student_id}', 'ThesisController@defense_comment');
    Route::post('/thesis/defense_comment/', 'ThesisController@defense_comment_store');

});

Route::group(['middleware' => ['auth', 'role:3'], 'namespace' => 'Admin', 'prefix' => 'admin'], function () {
    Route::get('/', 'HomeController@index')->name('admin');

    Route::get('/twowaychoice/{onlyUnselectedStudents?}', 'TwowayChoiceController@index');
    Route::get('/enforcechoice', 'TwowayChoiceController@edit');
    Route::post('/enforcechoice', 'TwowayChoiceController@store');

    Route::get('/setting/password', 'SettingController@edit_password');
    Route::post('/setting/password', 'SettingController@store_password');

    Route::get('/user/password', 'UserController@edit_password');
    Route::post('/user/password', 'UserController@store_password');
    Route::get('/user/add',  'UserController@add_user_edit');
    Route::post('/user/add', 'UserController@add_user');

    Route::get('/export/twowaychoice', 'TwowayChoiceController@export');

    Route::get('/thesis/statistic', 'ThesisController@statistic');
    Route::get('/thesis/download', 'ThesisController@download');

    Route::get('/thesis/export/{param}', 'ThesisController@export');


});

Route::resource('article', 'ArticleController');
Route::resource('template', 'TemplateController');
Route::get('download/templates/{filename}', function($filename) {
    return response()->download(base_path('public/uploads/templates/') . $filename);
});
Route::get('download/attach/{filename}', function($filename) {
    return response()->download(base_path('public/uploads/attach/') . $filename);
});

Route::get('download/descriptions/{filename}', function($filename) {
    return response()->download(base_path('public/uploads/descriptions/') . $filename);
});
Route::get('download/proposals/{filename}', function($filename) {
    return response()->download(base_path('public/uploads/proposals/') . $filename);
});
Route::get('download/papers/{filename}', function($filename) {
    return response()->download(base_path('public/uploads/papers/') . $filename);
});

Route::post('comment', 'CommentController@store_comment');
Route::get('comment', 'CommentController@fetch_comment');

Route::get('/download/cjd/{student_id}',  'DownLoadController@download_cjd');
Route::get('/download/dbzgscb/{student_id}',  'DownLoadController@down_dbzgscb');
Route::get('/download/pyrpsb/{student_id}',  'DownLoadController@down_pyrpsb');
Route::get('/download/all',  'DownLoadController@all');

Route::get('wx', 'WXToken@get');
